// pages/favorite/favorite.js
const jokesData = require('../../data/jokes');
Page({
  data: {
    favorites: []
  },
  onShow: function () {
    this.loadFavorites();
  },
  loadFavorites: function () {
    let favorites = wx.getStorageSync('favorites') || [];
    let favoriteJokes = jokesData.filter(joke => favorites.includes(joke.id));
    this.setData({
      favorites: favoriteJokes
    });
  },
  onJokeTap: function (e) {
    let jokeId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/joke-detail/joke-detail?id=' + jokeId
    });
  },
  onShareAppMessage: function () {
    return {
      title: '我的收藏的段子',
      path: '/pages/favorite/favorite'
    }
  }
})
